import os
import settings
from utilities import nc_constants

CELL_SIZE = 250
    
def GetAllLayers():
    from utilities import ensure_proper_name, ensure_abbreviated_name, isCOM, isCPFV, isDIV, isKYK, isPVT
    raster_path = os.path.join(settings.GIS_DATA_ROOT, 'analysis')
    layers = list()
    for group in Layers.GROUPS.keys():
        group_path = os.path.join(raster_path, group)
        for root, dirs, files in os.walk(group_path):
            for dir in dirs:
                tuple = dir.partition('_')
                species = tuple[0]
                port = tuple[2]
                fishing_type = nc_constants.FISHING_TYPES[group]  
                if isCOM(group):
                    take_methods = nc_constants.COMMERCIAL_METHODS[species]
                elif isCPFV(group):
                    take_methods = nc_constants.REC_CPFV_METHODS[species]
                elif isDIV(group):
                    take_methods = nc_constants.REC_DIV_METHODS[species]
                elif isKYK(group):
                    take_methods = nc_constants.REC_KYK_METHODS[species]
                elif isPVT(group):
                    take_methods = nc_constants.REC_PVT_METHODS[species]
                port_name = nc_constants.PORTS[port]
                port_abbr = port
                target_names = nc_constants.TARGETS[species]
                species_display_name = nc_constants.SPECIES_DISPLAY[species]
                species_abbr =  species
                group_name = ensure_proper_name(group)
                group_abbr = ensure_abbreviated_name(group)
                layer = Layer(group_name, group_abbr, CELL_SIZE, fishing_type, take_methods, port_name, port_abbr, species_display_name, species_abbr, target_names)
                layers.append(layer)      
    return layers
    

'''
A Layer represents a single fishing value layer which represents the
fishing value for a given species, by fisherman out of a given port/county
in a given fisherman user group.
'''
class Layer:
    def __init__(self, gn, ga, gcs, ft, tm, pn, pa, sn, sa, tn):
        self.group_name = gn
        self.group_abbr = ga
        self.cell_size = gcs
        self.fishing_type = ft
        self.take_methods = tm   
        self.port_name = pn
        self.port_abbr = pa
        self.species_name = sn
        self.species_abbr = sa      
        self.target_names = tn
        
